package com.example.myapplication.dao;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;

import java.net.URL;


public class RegisterDao {
    public int number;
    public boolean ischanged=false;
    public int register(String name, String account, String passwd) {
        new Thread(() -> {
            HttpURLConnection conn;
            try {
                URL url = new URL(HttpDao.urladd+"Register");
                conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("POST");

                //上传参数 实现post
                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(conn.getOutputStream());
                BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
                bufferedWriter.write("account=" + account + "&passwd=" + passwd + "&name=" + name);
                bufferedWriter.flush();
                //获得数据传入flag 并改变ischanged
                DataInputStream inputStream = new DataInputStream(conn.getInputStream());

                number = inputStream.readInt();
                ischanged=true;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }).start();
        return number;
    }


}
